package com.kreateinfinity.msdi.dao.authentication.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.kreateinfinity.msdi.dao.authentication.UserAuthenticationDAO;
import com.kreateinfinity.msdi.model.authentication.User;

@Repository("userAuthenticationDAO")
public class UserAuthenticationDAOImpl extends HibernateDaoSupport implements
UserAuthenticationDAO {

	private static Logger LOGGER = Logger.getLogger(UserAuthenticationDAOImpl.class);
	@SuppressWarnings("unchecked")
	@Override
	public User getLogin(String userName, String password) {
		System.out.println("test point 12");
		String sqlQuery = " from User user where user.userName = '" + userName.trim() + "' and user.userPassWord = '" + password.trim() + "'";
		LOGGER.debug("sqlQuery : " + sqlQuery);
		List<User> userList = this.getHibernateTemplate().find(sqlQuery);
		if(userList != null && userList.size()>0){
			LOGGER.debug("getUserId		: " + userList.get(0).getUserId());
			LOGGER.debug("getUserName	: " + userList.get(0).getUserName());
			LOGGER.debug("getUserPassWord: " + userList.get(0).getUserPassWord());
			LOGGER.debug("getFirstName	: " + userList.get(0).getFirstName());
			LOGGER.debug("getLastName	: " + userList.get(0).getLastName());
			LOGGER.debug("getAddress	: " + userList.get(0).getAddress());
			LOGGER.debug("getMobile		: " + userList.get(0).getMobile());
			LOGGER.debug("getUserEmail	: " + userList.get(0).getUserEmail());
			LOGGER.debug("getGender		: " + userList.get(0).getGender());
			LOGGER.debug("getPhone		: " + userList.get(0).getPhone());
			return userList.get(0);
		}else {
			LOGGER.debug("Invalid user name and password");
			return null;
		}
	}

}
